//Portions Copyright (C) 2011 Randall Shattuck
//Portions Copyright (C) 2007-2010 Owners of libeveapi 
//    (http://libeveapi.googlecode.com)
//
//EveDashboard.Api was forked from libeveapi 1.1.3
//
//This program is free software; you can redistribute it and/or modify it under
//the terms of the GNU General Public License as published by the Free Software 
//Foundation; either version 2 of the License, or (at your option) any later 
//version.
//
//This program is distributed in the hope that it will be useful, but WITHOUT 
//ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
//FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
//details. You should have received a copy of the GNU General Public License 
//along with this program; if not, write to the Free Software Foundation, Inc.,
//59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//-----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace EveDashboard.Api
{
    class TimeUtilities
    {
        /// <summary>
        /// Converts a CCP API date/time string to a UTC DateTime
        /// </summary>
        /// <param name="timeUTC"></param>
        /// <returns></returns>
        public static DateTime ConvertCCPTimeStringToDateTimeUTC(string timeUTC)
        {
            // timeUTC  = yyyy-mm-dd hh:mm:ss
            if (timeUTC == null || timeUTC == "")
                return DateTime.MinValue;

            DateTime dt = new DateTime(
                            Int32.Parse(timeUTC.Substring(0, 4)),
                            Int32.Parse(timeUTC.Substring(5, 2)),
                            Int32.Parse(timeUTC.Substring(8, 2)),
                            Int32.Parse(timeUTC.Substring(11, 2)),
                            Int32.Parse(timeUTC.Substring(14, 2)),
                            Int32.Parse(timeUTC.Substring(17, 2)),
                            0,
                            DateTimeKind.Utc);
            return dt;
        }

        public  static DateTime GetCacheExpiryUTC(DateTime cacheUntil, DateTime CCPCurrent)
        {
            return DateTime.Now.ToUniversalTime() + (cacheUntil - CCPCurrent);
        }

        public static DateTime ConvertCCPToLocalTime(DateTime ccpDateTime)
        {
            return ccpDateTime.ToLocalTime();
        }
    }
}
